<?xml version="1.0"?>

<xsl:stylesheet
  version="1.0"
  exclude-result-prefixes="doc"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
  xmlns:dt="http://xsltsl.org/date-time"
>
  <xsl:include href="../date-time.xsl"/>

  <doc:article>
    <doc:title>Date/Time Module Test Suite</doc:title>
    <doc:para>This stylesheet tests the date-time stylesheet module.</doc:para>
  </doc:article>

  <xsl:template name="date-time">

    <xsl:message>Date/Time tests starting</xsl:message>
    <xsl:text>&#10;&#10;Running date-time tests&#10;&#10;</xsl:text>

    <xsl:message>Test dt:format-date-time template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:format-date-time test (with default format)</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:format-date-time">
          <xsl:with-param name="year" select="2001"/>
          <xsl:with-param name="month" select="3"/>
          <xsl:with-param name="day" select="29"/>
          <xsl:with-param name="hour" select="19"/>
          <xsl:with-param name="minute" select="26"/>
          <xsl:with-param name="second" select="17"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="'2001-03-29T19:26:17'"/>
    </xsl:call-template>


    <xsl:message>Test dt:format-date-time template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:format-date-time test</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:format-date-time">
          <xsl:with-param name="year" select="1999"/>
          <xsl:with-param name="month" select="4"/>
          <xsl:with-param name="day" select="1"/>
          <xsl:with-param name="hour" select="12"/>
          <xsl:with-param name="minute" select="0"/>
          <xsl:with-param name="second" select="0"/>
          <xsl:with-param name="format" select="'%A, %b %d, %Y'"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="'Thursday, Apr 01, 1999'"/>
    </xsl:call-template>


    <xsl:message>Test dt:format-date-time template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:format-date-time test</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:format-date-time">
          <xsl:with-param name="year" select="1"/>
          <xsl:with-param name="month" select="2"/>
          <xsl:with-param name="day" select="3"/>
          <xsl:with-param name="hour" select="4"/>
          <xsl:with-param name="minute" select="5"/>
          <xsl:with-param name="second" select="6"/>
          <xsl:with-param name="format" select="'%a %A %b %B %d %H %m %M %S %w %Y %%'"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="'Sat Saturday Feb February 03 04 02 05 06 6 0001 %'"/>
    </xsl:call-template>


    <xsl:message>Test dt:calculate-day-of-the-week template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:calculate-day-of-the-week test</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:calculate-day-of-the-week">
          <xsl:with-param name="year" select="1974"/>
          <xsl:with-param name="month" select="5"/>
          <xsl:with-param name="day" select="27"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="1"/>
    </xsl:call-template>


    <xsl:message>Test dt:calculate-julian-day template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:calculate-julian-day test</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:calculate-julian-day">
          <xsl:with-param name="year" select="2000"/>
          <xsl:with-param name="month" select="1"/>
          <xsl:with-param name="day" select="1"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="2451545"/>
    </xsl:call-template>


    <xsl:message>Test dt:format-julian-day template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:format-julian-day test</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:format-julian-day">
          <xsl:with-param name="julian-day" select="2451545"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="'2000-01-01'"/>
    </xsl:call-template>


    <xsl:message>Test dt:calculate-week-number template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:calculate-week-number test</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:calculate-week-number">
          <xsl:with-param name="year" select="2000"/>
          <xsl:with-param name="month" select="1"/>
          <xsl:with-param name="day" select="1"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="52"/>
    </xsl:call-template>


    <xsl:message>Test dt:calculate-week-number template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:calculate-week-number test</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:calculate-week-number">
          <xsl:with-param name="year" select="2001"/>
          <xsl:with-param name="month" select="1"/>
          <xsl:with-param name="day" select="1"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="1"/>
    </xsl:call-template>


    <xsl:message>Test dt:calculate-week-number template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:calculate-week-number test</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:calculate-week-number">
          <xsl:with-param name="year" select="2001"/>
          <xsl:with-param name="month" select="1"/>
          <xsl:with-param name="day" select="8"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="2"/>
    </xsl:call-template>


    <xsl:message>Test dt:calculate-week-number template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:calculate-week-number test</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:calculate-week-number">
          <xsl:with-param name="year" select="1996"/>
          <xsl:with-param name="month" select="12"/>
          <xsl:with-param name="day" select="31"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="1"/>
    </xsl:call-template>


    <!-- Most years have 52 weeks, but years that start
    on a Thursday and leap years that start on a Wednesday
    have 53 weeks. -->

    <xsl:message>Test dt:calculate-week-number template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:calculate-week-number test</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:calculate-week-number">
          <xsl:with-param name="year" select="1998"/>
          <xsl:with-param name="month" select="12"/>
          <xsl:with-param name="day" select="31"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="53"/>
    </xsl:call-template>


    <xsl:message>Test dt:calculate-week-number template</xsl:message>

    <xsl:call-template name="test">
      <xsl:with-param name="description">dt:calculate-week-number test</xsl:with-param>
      <xsl:with-param name="result">
        <xsl:call-template name="dt:calculate-week-number">
          <xsl:with-param name="year" select="1992"/>
          <xsl:with-param name="month" select="12"/>
          <xsl:with-param name="day" select="31"/>
        </xsl:call-template>
      </xsl:with-param>
      <xsl:with-param name="expect" select="53"/>
    </xsl:call-template>

  </xsl:template>

</xsl:stylesheet>
